package com.k.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.k.demo.entity.RedBag;
import com.k.demo.entity.RedBagRecord;
import com.k.demo.mapper.RedBagMapper;
import com.k.demo.mapper.RedBagRecordMapper;
import com.k.demo.service.RedBagRecordService;


@Service
public class RedBagRecordServiceImpl implements RedBagRecordService {
	
	@Autowired
	private RedBagRecordMapper redBagRecordMapper;
	@Autowired
	private RedBagMapper redbagMapper;

	@Override
	public List<RedBagRecord> getAll(int user_id) {
		// TODO Auto-generated method stub
		return redBagRecordMapper.selectAll(user_id);
	}
	@Override
	public List<RedBagRecord> getByState(int state, int user_id) {
		// TODO Auto-generated method stub
		return redBagRecordMapper.selectByState(state, user_id);
	}

	@Override
	public int changeState(int state, int user_id, int red_bag_record_id) {
		// TODO Auto-generated method stub
		return redBagRecordMapper.updateState(state, user_id, red_bag_record_id);
	}

	//领取红包后新增一条红包记录
	public int addRedBagRecord(RedBagRecord redBagRecord) {
		
		return redBagRecordMapper.addRedBagRecord(redBagRecord);
		
	}

	//传入userid，返回当前用户的红包记录
	public List<RedBagRecord> getByUserId(Integer user_id) {
		
		return redBagRecordMapper.selectByUserId(user_id);
	}

	@Override
	public PageInfo<RedBagRecord> searchResultWithPage(int pageNum, int pageSize, RedBagRecord redBagRecord) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<RedBagRecord>(redBagRecordMapper.selectByRecord(redBagRecord));
	}
	@Override
	public List<RedBagRecord> getAllUserRecords() {
		// TODO Auto-generated method stub
		return redBagRecordMapper.getAllUserRecoed();
	}
	@Override
	public Double getTotalValueByDate(String date) {
		// TODO Auto-generated method stub
						
		return redBagRecordMapper.getTotalValueByDate(date);
	}
	
	//返回当前用户的可用红包数量
	public int getUserRedBagRecordAmount(int user_id) {
		
		
		return redBagRecordMapper.getUserRedBagRecordAmount(user_id);
	}

	
	

}
